home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / sockcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-03  |  3.5 KB  |  155 lines

  1. /* Socket status display code
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include <dos.h>
  6. #include "global.h"
  7. #include "config.h"
  8. #include "mbuf.h"
  9. #include "proc.h"
  10. #include "lzw.h"
  11. #include "usock.h"
  12. #include "socket.h"
  13. #include "ax25.h"
  14. #include "netrom.h"
  15. #include "tcp.h"
  16. #include "udp.h"
  17. #include "commands.h"
  18. #include "config.h"
  19.  
  20. /* Socket status display command */
  21. int
  22. dosock(argc,argv,p)
  23. int argc;
  24. char *argv[];
  25. void *p;
  26. {
  27.     register struct usock *up;
  28.     int s,i;
  29.     struct sockaddr fsock;
  30.     char *cp;
  31.  
  32.     if(argc < 2){
  33. #ifndef TNOS_68K
  34.         tprintf("S#  Type    PCB  Remote socket         Owner\n");
  35. #else
  36.         tprintf("S#  Type    PCB       Remote socket        Owner\n");
  37. #endif
  38.         for(s=SOCKBASE;s<Nusock+SOCKBASE;s++){
  39.             up = itop(s);
  40.             if(up == NULLUSOCK)
  41.                 continue;
  42.  
  43.             i = sizeof(fsock);
  44.             if(getpeername(s,(char *)&fsock,&i) == 0 && i != 0)
  45.                 cp = psocket(&fsock);
  46.             else
  47.                 cp = "";
  48.  
  49. #ifndef TNOS_68K
  50.             tprintf("%3d %-8s%4.4x %-22s%4.4x %-10s\n",
  51. #else
  52.             tprintf("%3d %-8s%-8.8x %-22s%-8.8x %-10s\n",
  53. #endif
  54.              s,Socktypes[up->type],FP_SEG(up->cb.p),cp,
  55.              FP_SEG(up->owner),up->owner->name);
  56.         }
  57.         return 0;
  58.     }
  59.     s = atoi(argv[1]);
  60.     if(s < SOCKBASE || s >= Nusock+SOCKBASE){
  61.         tprintf("Number out of range\n");
  62.         return 1;
  63.     }
  64.     up = itop(s);
  65.     if(up == NULLUSOCK){
  66.         tprintf("Socket not in use\n");
  67.         return 0;
  68.     }
  69.     tprintf("%s %4.4x %s",Socktypes[up->type],FP_SEG(up->cb.p),
  70.      up->flag == SOCK_ASCII ? "ascii" : "binary");
  71.     if(up->eol[0] != '\0'){
  72.         tprintf(" eol seq:");
  73.         for(i=0;up->eol[i] != '\0' && i<sizeof(up->eol);i++)
  74.             tprintf(" %02x",up->eol[i]);
  75.     }
  76.     tprintf("  Since: %s",ctime(&up->created));
  77.     if(up->cb.p == NULL)
  78.         return 0;
  79.     switch(up->type){
  80.     case TYPE_RAW:
  81.     case TYPE_LOCAL_DGRAM:
  82.         tprintf("Inqlen: %d packets\n",socklen(s,0));
  83.         tprintf("Outqlen: %d packets\n",socklen(s,1));
  84.         break;
  85.     case TYPE_LOCAL_STREAM:
  86.         tprintf("Inqlen: %d bytes\n",socklen(s,0));
  87.         tprintf("Outqlen: %d bytes\n",socklen(s,1));
  88.         break;
  89.     case TYPE_TCP:
  90.         st_tcp(up->cb.tcb);
  91.         break;
  92.     case TYPE_UDP:
  93.         st_udp(up->cb.udp,0);
  94.         break;
  95. #ifdef    AX25
  96.     case TYPE_AX25I:
  97.         st_ax25(up->cb.ax25);
  98.         break;
  99. #endif
  100. #ifdef    NETROM
  101.     case TYPE_NETROML4:
  102.         donrdump(up->cb.nr4);
  103.         break;
  104. #endif
  105.     }
  106. #ifdef LZW
  107.     if(up->zout != NULLLZW)
  108.         tprintf("Compressed %ld bytes. (%s mode - %d/%-d)\n",up->zout->cnt, up->zout->mode ? "fast" : "compact", up->zout->codebits, up->zout->maxbits);
  109.     if(up->zin != NULLLZW)
  110.         tprintf("Decompressed %ld bytes. (%s mode - %d/%-d)\n",up->zin->cnt, up->zin->mode ? "fast" : "compact", up->zin->codebits, up->zin->maxbits);
  111. #endif
  112.     return 0;
  113. }
  114.  
  115. /* Kick the session related to a particular socket
  116.  * this is easier then the tcp kick, ax25 kick, etc... commands
  117.  * 920117 - WG7J
  118.  */
  119. int
  120. dokicksocket(argc,argv,p)
  121. int argc;
  122. char *argv[];
  123. void *p;
  124. {
  125.     register struct usock *up;
  126.     int s;  /*socket to kick*/
  127.     int retval=0;
  128.  
  129.     s = atoi(argv[1]);
  130.     if(s < SOCKBASE || s >= Nusock+SOCKBASE){
  131.         tputs("Number out of range\n");
  132.         return 1;
  133.     }
  134.     up = itop(s);
  135.     if(up == NULLUSOCK){
  136.         tputs("Socket not in use\n");
  137.         return 0;
  138.     }
  139.     if(up->type == TYPE_TCP)
  140.         retval = kick_tcp(up->cb.tcb);
  141. #ifdef AX25
  142.     if(up->type == TYPE_AX25I)
  143.         retval = kick_ax25(up->cb.ax25);
  144. #endif
  145. #ifdef NETROM
  146.     if(up->type == TYPE_NETROML4)
  147.         retval = kick_nr4(up->cb.nr4);
  148. #endif
  149.     if(retval == -1)
  150.         tputs("Kick not successfull\n");
  151.     return 0;
  152. }
  153.  
  154.  
  155.